/*
 * @(#)NoticeBOImpl.java $version 2013-3-4
 * 
 * Copyright 2013 NADO Group. All rights Reserved.
 * NADO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nado.iims2.community.bo.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nado.extensions.util.DataMap;
import com.nado.iims2.community.bo.NoticeBO;
import com.nado.iims2.community.dao.NoticeDAO;
import com.nado.iims2.community.model.NoticeModel;

/**
 * The Class NoticeBOImpl.
 * 
 * @author nado
 */
@Service("NoticeBO")
public class NoticeBOImpl implements NoticeBO {
	/** The log. */
	private static Log log = LogFactory.getLog(NoticeBOImpl.class);
	
	/** The notice dao. */
	@Autowired
	private NoticeDAO noticeDAO = null;
	
	@Override
	public List<DataMap> getNoticeList(String startDate, String endDate,
			String typeCd, int offset, int count) {
		try {
			List<DataMap> result = new ArrayList<DataMap>();
			result = noticeDAO.selectNoticeList(startDate, endDate, typeCd, offset, count);
			return result;
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<DataMap>();
		}
	}

	@Override
	public int getNoticeListCount(String startDate, String endDate,
			String typeCd) {
		try {
			return noticeDAO.selectNoticeListCount(startDate, endDate, typeCd);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
	}

	@Override
	public NoticeModel getNoticeDetail(int noticeNo) {
		try {
			NoticeModel model = new NoticeModel();
			model = noticeDAO.selectNoticeDetail(noticeNo);
			return model;
		} catch (Exception e) {
			log.error(e, e);
			return null;
		}
	}

	@Override
	public int writeNotice(NoticeModel model) {
		int result = 0;
		try {
			if(model.getNoticeNo() != 0) {
				result = noticeDAO.updateNotice(model);
			} else {
				result = noticeDAO.insertNotice(model);
			}
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
		
		return result;
	}

	@Override
	public int removeNotice(int noticeNo) {
		return 0;
	}

}
